package ng.lib;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.swing.ImageIcon;

public class Utils {

	public static final boolean DRAW_ENERGIES = false;
	
	public static BufferedImage[] imageLodaer(String[] src) throws IOException {
		BufferedImage img[] = new BufferedImage[src.length];
		for (int i = 0; i < img.length; ++i) {
			URL u = Utils.class.getClass().getResource("/" + src[i].trim());
			Image _img;
			if (u != null) {
				_img = new ImageIcon(u).getImage();
			} else {
				_img = new ImageIcon(src[i]).getImage();
			}
			img[i] = new BufferedImage(_img.getWidth(null), _img
					.getHeight(null), BufferedImage.TYPE_4BYTE_ABGR_PRE);
			Graphics g = img[i].getGraphics();
			g.drawImage(_img, 0, 0, null);

		}
		return img;
	}

	public static BufferedImage imageLodaer(String src) throws IOException {
		BufferedImage img;
		URL u = Utils.class.getClass().getResource("/" + src.trim());
		Image _img;
		if (u != null) {
			_img = new ImageIcon(u).getImage();
		} else {
			_img = new ImageIcon(src).getImage();
		}
		img = new BufferedImage(_img.getWidth(null), _img.getHeight(null),
				BufferedImage.TYPE_4BYTE_ABGR_PRE);
		Graphics g = img.getGraphics();
		g.drawImage(_img, 0, 0, null);

		return img;
	}

	public BufferedImage rotateImage(BufferedImage src, double degrees) {
		AffineTransform affineTransform = AffineTransform.getRotateInstance(
				Math.toRadians(degrees), src.getWidth() / 2,
				src.getHeight() / 2);
		BufferedImage rotatedImage = new BufferedImage(src.getWidth(), src
				.getHeight(), src.getType());
		Graphics2D g = (Graphics2D) rotatedImage.getGraphics();
		g.setTransform(affineTransform);
		g.drawImage(src, 0, 0, null);
		return rotatedImage;
	}

}